
var SoundLine = {
    
    createNew: function (source, direction, patternImg) {
        // var beams = new Array(10);
        // for (var i = 0; i < beams.length; i++) {
        //     beams[i] = new Kinetic.Rect({
        //         x: source[0] + i*20 * Math.cos(direction),
        //         y: source[1] + i*20 * Math.sin(direction),
        //         width: 160,
        //         rotation: direction,
        //         height: 2,
        //         opacity: 1
        //     });
        // };
        
        
        var beam = new Kinetic.Rect({
                x: source[0],
                y: source[1],
                width: 20,
                height: 2,
                rotation: direction,
                fill: 'white',
                fillPriority: 'pattern',
                fillPatternX: 0,
                fillPatternY: 0,
                fillPatternImage: patternImg,
                fillPatternRepeat: 'no-repeat',
                opacity: 1
            });
        // set fill pattern image<br>
        // beam.rotation(direction);
        
        beam.runAway = function (layer){
            this.anim = new Kinetic.Animation(function(frame) {
                beam.setWidth(20 + frame.time/10);
                beam.fillPatternScaleX((200 + frame.time/10)/200);
                beam.opacity(1 - frame.time/4000);
                console.log(beam.opacity());
                if(frame.time > 4000){
                    beam.anim.stop();
                    beam.destroy();
                }             
            }, layer);
            this.anim.start();
        };
        beam.stopRun = function () {
            this.anim.stop();
            this.destroy();
            console.log('Enter stopRun');
        };
        
        return beam;
    }
}


